package com.xdb.sqlparser.dialect.oracle.ast.statement;

import com.xdb.sqlparser.ast.SQLOrderingSpecification;
import com.xdb.sqlparser.ast.statement.SQLSelectOrderByItem;
import com.xdb.sqlparser.dialect.oracle.visitor.OracleASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;

public class OracleOrderByItem extends SQLSelectOrderByItem {

	public OracleOrderByItem() {

	}

	protected void accept0(SQLAstVisitor visitor) {
		if (visitor instanceof OracleASTVisitor) {
			accept0((OracleASTVisitor) visitor);
		} else {
			super.accept0(visitor);
		}
	}

	protected void accept0(OracleASTVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.expr);
		}

		visitor.endVisit(this);
	}

	public void output(StringBuffer buf) {
		this.expr.output(buf);
		if (SQLOrderingSpecification.ASC.equals(this.type)) {
			buf.append(" ASC");
		} else if (SQLOrderingSpecification.DESC.equals(this.type)) {
			buf.append(" DESC");
		}
		if (NullsOrderType.NullsFirst.equals(this.nullsOrderType)) {
			buf.append(" NULLS FIRST");
		} else if (NullsOrderType.NullsLast.equals(this.nullsOrderType)) {
			buf.append(" NULLS LAST");
		}
	}

}
